package com.calmcar.adas.service;

import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;

import com.calmcar.adas.apiserver.out.CvCameraViewFrame;

/**
 * Created by lelexiao on 2018/5/8.
 * modify by wwnxiao 20180814
 */

public class AdasServicePool {
    public HandlerThread handlerThreadLaneCar;
    public Handler handlerLaneCar = null;

    public LaneCarDataListener getLaneCarDataListener() {
        return laneCarDataListener;
    }

    public void setLaneCarDataListener(LaneCarDataListener laneCarDataListener) {
        this.laneCarDataListener = laneCarDataListener;
    }

    public LaneCarDataListener laneCarDataListener;

    public void createHandlerLaneCar() {
        if(handlerThreadLaneCar!=null )  return;
        handlerThreadLaneCar = new HandlerThread("lane_car");
        handlerThreadLaneCar.start();
        handlerLaneCar= new Handler(handlerThreadLaneCar .getLooper()) {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                laneCarDataListener.onProcessData((CvCameraViewFrame) msg.obj);
            }
        };
    }

    public void sendLaneCarData(CvCameraViewFrame inputStream) {
        if (handlerThreadLaneCar!= null && inputStream != null) {
            handlerLaneCar.removeMessages(1);
            Message msg = Message.obtain(handlerLaneCar, 1, inputStream);
            boolean isOk = handlerLaneCar.sendMessage(msg);
        }
    }

    public void stopLaneService() {
        handlerLaneCar.removeMessages(1);
        handlerThreadLaneCar.quit();
        handlerThreadLaneCar=null;

    }

    public interface LaneCarDataListener {
        void onProcessData(CvCameraViewFrame data);
    }



}
